<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="名称" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="创建日期">
        <el-date-picker v-model="daterangeCreateDate" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item label="规格" prop="sequence">
        <el-input v-model="queryParams.specification" placeholder="请输入规格" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="序列" prop="sequence">
        <el-input v-model="queryParams.sequence" placeholder="请输入序列" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="产品描述" prop="description">
        <el-input v-model="queryParams.description" placeholder="请输入库存描述" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="采购说明" prop="descriptionPurchase">
        <el-input v-model="queryParams.descriptionPurchase" placeholder="请输入采购描述" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="销售描述" prop="descriptionSale">
        <el-input v-model="queryParams.descriptionSale" placeholder="请输入销售描述" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="库存类型" prop="type">
        <el-select v-model="queryParams.type" placeholder="请选择类型" clearable>
          <el-option v-for="dict in dict.type.product_type" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item> -->
      <el-form-item label="内部类别" prop="categId">
        <el-select v-model="queryParams.categId" placeholder="请选择内部类别" clearable>
          <el-option v-for="dict in dict.type.product_category" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="售价" prop="listPrice">
        <el-input v-model="queryParams.listPrice" placeholder="请输入售价" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="体积(kg)" prop="volume">
        <el-input v-model="queryParams.volume" placeholder="请输入体积" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="重量(m³)" prop="weight">
        <el-input v-model="queryParams.weight" placeholder="请输入重量" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="可用于销售" prop="saleOk">
        <el-select v-model="queryParams.saleOk"  placeholder="请选择" clearable  @keyup.enter.native="handleQuery" >
          <el-option v-for="item in yesOrnot" :key="item.id" :label="item.name" :value="item.id" />
        </el-select>
        
      </el-form-item>
      <el-form-item label="可用于采购" prop="purchaseOk">
        <el-select v-model="queryParams.purchaseOk" filterable placeholder="请选择" clearable  @keyup.enter.native="handleQuery" >
          <el-option v-for="item in yesOrnot" :key="item.id" :label="item.name" :value="item.id" />
        </el-select>
       
      </el-form-item> -->
      <!-- <el-form-item label="Unit of Measure" prop="uomId">
        <el-input v-model="queryParams.uomId" placeholder="请输入Unit of Measure" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="Active" prop="active">
        <el-input v-model="queryParams.active" placeholder="请输入Active" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="颜色" prop="color">
        <el-input v-model="queryParams.color" placeholder="请输入颜色" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="创建者id" prop="createUid">
        <el-input v-model="queryParams.createUid" placeholder="请输入创建者id" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="创建日期">
        <el-date-picker v-model="daterangeCreateDate" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item label="最后更新者id" prop="writeUid">
        <el-input v-model="queryParams.writeUid" placeholder="请输入最后更新者id" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="最后更新日期">
        <el-date-picker v-model="daterangeWriteDate" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item> -->
      <!-- <el-form-item label="可用于费用" prop="canBeExpensed">
        <el-select v-model="queryParams.canBeExpensed" filterable placeholder="请选择" clearable  @keyup.enter.native="handleQuery" >
          <el-option v-for="item in yesOrnot" :key="item.id" :label="item.name" :value="item.id" />
        </el-select>
       
      </el-form-item> -->
      <!-- <el-form-item label="仓库(海内外)" prop="warehouse">
        <el-input v-model="queryParams.warehouse" placeholder="请输入仓库(海内外)" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['system:stock:edit']">修改</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['system:stock:remove']">删除</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="stockList" @selection-change="handleSelectionChange" @row-click="detail">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="名称" align="center" prop="name" />
      <el-table-column label="规格" align="center" prop="specification" />
      <el-table-column label="单位" align="center" prop="uomId">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.stock_uom" :value="scope.row.uomId" />
        </template>
      </el-table-column>
      <!-- <el-table-column label="库存类型" align="center" prop="type">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.product_type" :value="scope.row.type" />
        </template>
      </el-table-column> -->
      <el-table-column label="内部类别" align="center" prop="categId">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.product_category" :value="scope.row.categId" />
        </template>
      </el-table-column>
      <!-- <el-table-column label="序列" align="center" prop="sequence" /> -->
      <!-- <el-table-column label="产品描述" align="center" prop="description" />
      <el-table-column label="采购说明" align="center" prop="descriptionPurchase" />
      <el-table-column label="销售描述" align="center" prop="descriptionSale" /> -->


      <!-- <el-table-column label="售价" align="center" prop="listPrice" />
      <el-table-column label="体积(kg)" align="center" prop="volume" />
      <el-table-column label="重量(m³)" align="center" prop="weight" />
      <el-table-column label="可用于销售" align="center" prop="saleOk" />
      <el-table-column label="可用于采购" align="center" prop="purchaseOk" />
      
      <el-table-column label="Active" align="center" prop="active" />
      <el-table-column label="颜色" align="center" prop="color" />
      <el-table-column label="创建者id" align="center" prop="createUid" /> -->

      <el-table-column label="创建日期" align="center" prop="createDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="最后更新者id" align="center" prop="writeUid" /> -->
      <!-- <el-table-column label="最后更新日期" align="center" prop="writeDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.writeDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->

      <!-- <el-table-column label="可用于费用" align="center" prop="canBeExpensed" /> -->
      <!-- <el-table-column label="仓库(海内外)" align="center" prop="warehouse" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" @click.stop>
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-document" @click.stop="detail(scope.row)">详情</el-button>
          <!-- <el-button size="mini" type="text" icon="el-icon-document" @click="Operationdetail(scope.row)"
            v-hasPermi="['system:stock:edit']">操作详情</el-button> -->
          <el-button size="mini" type="text" icon="el-icon-edit" @click.stop="handleUpdate(scope.row)">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click.stop="handleDelete(scope.row)"
            v-hasPermi="['system:stock:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加库存对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <!-- <el-form-item label="id" prop="id">
          <el-input v-model="form.id" placeholder="请输入id" />
        </el-form-item> -->
        <el-form-item label="产品名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入产品名称" />
        </el-form-item>
        <el-form-item label="规格" prop="specification">
          <el-input v-model="form.specification" placeholder="请输入规格" />
        </el-form-item>
        <el-form-item label="单位" prop="uomId">
          <el-select  clearable v-model="form.uomId" filterable placeholder="请选择单位" >
            <el-option v-for=" dict in dict.type.stock_uom" :key="dict.value" :label="dict.label"
              :value="parseInt(dict.value)" />
          </el-select>
          <!-- <el-input v-model="form.uomId" placeholder="请输入单位" /> -->
        </el-form-item>
        <!-- <el-form-item label="序列" prop="sequence">
          <el-input v-model="form.sequence" placeholder="请输入序列" />
        </el-form-item> -->
        <el-form-item label="产品描述" prop="description">
          <el-input v-model="form.description" placeholder="请输入库存描述" />
        </el-form-item>
        <!-- <el-form-item label="采购说明" prop="descriptionPurchase">
          <el-input v-model="form.descriptionPurchase" placeholder="请输入采购描述" />
        </el-form-item> -->
        <!-- <el-form-item label="销售描述" prop="descriptionSale">
          <el-input v-model="form.descriptionSale" placeholder="请输入销售描述" />
        </el-form-item> -->
        <!-- <el-form-item label="库存类型" prop="type">
          <el-input v-model="form.type" placeholder="请输入库存类型" />
          
        </el-form-item> -->
        <el-form-item label="内部类别" prop="categId">
          <el-select clearable filterable v-model="form.categId" placeholder="请选择内部类别">
            <el-option v-for="dict in dict.type.product_category" :key="dict.value" :label="dict.label"
              :value="parseInt(dict.value)"></el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="售价" prop="listPrice">
          <el-input v-model="form.listPrice" placeholder="请输入售价" />
        </el-form-item> -->
        <el-form-item label="体积(m³)" prop="volume">
          <el-input v-model="form.volume" placeholder="请输入体积" />
        </el-form-item>
        <el-form-item label="重量(kg)" prop="weight">
          <el-input v-model="form.weight" placeholder="请输入重量" />
        </el-form-item>
        <el-form-item label="可用于销售" prop="saleOk">
          <!-- <el-input v-model="form.saleOk" placeholder="请输入可用于销售" /> -->
          <el-radio v-model="form.saleOk" label="t">是</el-radio>
          <el-radio v-model="form.saleOk" label="f">否</el-radio>
        </el-form-item>
        <el-form-item label="可用于采购" prop="purchaseOk">
          <!-- <el-input v-model="form.purchaseOk" placeholder="请输入可用于采购" /> -->
          <el-radio v-model="form.purchaseOk" label="t">是</el-radio>
          <el-radio v-model="form.purchaseOk" label="f">否</el-radio>
        </el-form-item>
        <el-form-item label="可用于费用" prop="canBeExpensed">
          <!-- <el-input v-model="form.canBeExpensed" placeholder="请输入可用于费用" /> -->
          <el-radio v-model="form.canBeExpensed" label="t">是</el-radio>
          <el-radio v-model="form.canBeExpensed" label="f">否</el-radio>
        </el-form-item>

        <!-- <el-form-item label="Active" prop="active">
          <el-input v-model="form.active" placeholder="请输入Active" />
        </el-form-item> -->
        <el-form-item label="颜色" prop="color">
          <el-input v-model="form.color" placeholder="请输入颜色" />
        </el-form-item>
        <!-- <el-form-item label="创建者id" prop="createUid">
          <el-input v-model="form.createUid" placeholder="请输入创建者id" />
        </el-form-item> -->
        <!-- <el-form-item label="创建日期" prop="createDate">
          <el-date-picker clearable v-model="form.createDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择创建日期">
          </el-date-picker>
        </el-form-item> -->
        <!-- <el-form-item label="最后更新者id" prop="writeUid">
          <el-input v-model="form.writeUid" placeholder="请输入最后更新者id" />
        </el-form-item> -->
        <!-- <el-form-item label="最后更新日期" prop="writeDate">
          <el-date-picker clearable v-model="form.writeDate" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择最后更新日期">
          </el-date-picker>
        </el-form-item> -->

        <el-form-item label="初始库存" prop="quantyWhenInsert">
          <el-input v-model.number="form.quantyWhenInsert" placeholder="请输入初始库存" />
        </el-form-item>

        <!-- <el-form-item label="仓库(海内外)" prop="warehouse">
          <el-radio v-model="form.warehouse" label="国内">国内仓</el-radio>
          <el-radio v-model="form.warehouse" label="海外">海外仓</el-radio>
        </el-form-item>
        <el-form-item label="库存不足预警数量" prop="productMinQty">
          <el-input v-model.number="form.productMinQty" placeholder="请输入库存不足预警数量" />
        </el-form-item>
        <el-form-item label="补货推荐数量" prop="productMaxQty">
          <el-input v-model.number="form.productMaxQty" placeholder="请输入补货推荐数量" />
        </el-form-item>
        <el-form-item label="供应商" prop="partnerId">
          <el-select v-model="form.partnerId" filterable placeholder="请选择供应商">
            <el-option v-for="item in supplierdata" :key="item.id" :label="item.name" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="最低采购数量" prop="purchaseMinQty">
          <el-input v-model.number="form.purchaseMinQty" placeholder="请输入最低采购数量" />
        </el-form-item>
        <el-form-item label="供应商报价" prop="price">
          <el-input v-model="form.price" placeholder="请输入供应商报价" />
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 修改库存对话框 -->
    <el-dialog :title="title" :visible.sync="openedit" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules2" label-width="150px">
        <!-- <el-form-item label="id" prop="id">
          <el-input v-model="form.id" placeholder="请输入id" />
        </el-form-item> -->
        <el-form-item label="产品名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入产品名称" />
        </el-form-item>
        <el-form-item label="规格" prop="specification">
          <el-input v-model="form.specification" placeholder="请输入规格" />
        </el-form-item>
        <el-form-item label="单位" prop="uomId">
          <el-select  v-model="form.uomId" filterable placeholder="请选择单位" clearable>
            <el-option v-for=" dict in dict.type.stock_uom" :key="dict.value" :label="dict.label"
              :value="parseInt(dict.value)" />
          </el-select>
          <!-- <el-input v-model="form.uomId" placeholder="请输入单位" /> -->
        </el-form-item>
        <!-- <el-form-item label="序列" prop="sequence">
          <el-input v-model="form.sequence" placeholder="请输入序列" />
        </el-form-item> -->
        <el-form-item label="产品描述" prop="description">
          <el-input v-model="form.description" placeholder="请输入库存描述" />
        </el-form-item>
        <!-- <el-form-item label="采购说明" prop="descriptionPurchase">
          <el-input v-model="form.descriptionPurchase" placeholder="请输入采购描述" />
        </el-form-item> -->
        <!-- <el-form-item label="销售描述" prop="descriptionSale">
          <el-input v-model="form.descriptionSale" placeholder="请输入销售描述" />
        </el-form-item> -->
        <!-- <el-form-item label="库存类型" prop="type"> -->
        <!-- <el-input v-model="form.type" placeholder="请输入库存类型" /> -->
        <!-- <el-select v-model="form.type" placeholder="请选择类型">
            <el-option v-for="dict in dict.type.product_type" :key="dict.value" :label="dict.label"
              :value="dict.value"></el-option>
          </el-select> -->
        <!-- </el-form-item> -->
        <el-form-item label="内部类别" prop="categId">
          <el-select clearable v-model="form.categId" placeholder="请选择内部类别" filterable>
            <el-option v-for="dict in dict.type.product_category" :key="dict.value" :label="dict.label"
              :value="parseInt(dict.value)"></el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="售价" prop="listPrice">
          <el-input v-model="form.listPrice" placeholder="请输入售价" />
        </el-form-item> -->
        <el-form-item label="体积(m³)" prop="volume">
          <el-input v-model="form.volume" placeholder="请输入体积" />
        </el-form-item>
        <el-form-item label="重量(kg)" prop="weight">
          <el-input v-model="form.weight" placeholder="请输入重量" />
        </el-form-item>
        <el-form-item label="可用于销售" prop="saleOk">
          <!-- <el-input v-model="form.saleOk" placeholder="请输入可用于销售" /> -->
          <el-radio v-model="form.saleOk" label="t">是</el-radio>
          <el-radio v-model="form.saleOk" label="f">否</el-radio>
        </el-form-item>
        <el-form-item label="可用于采购" prop="purchaseOk">
          <!-- <el-input v-model="form.purchaseOk" placeholder="请输入可用于采购" /> -->
          <el-radio v-model="form.purchaseOk" label="t">是</el-radio>
          <el-radio v-model="form.purchaseOk" label="f">否</el-radio>
        </el-form-item>
        <el-form-item label="可用于费用" prop="canBeExpensed">
          <!-- <el-input v-model="form.canBeExpensed" placeholder="请输入可用于费用" /> -->
          <el-radio v-model="form.canBeExpensed" label="t">是</el-radio>
          <el-radio v-model="form.canBeExpensed" label="f">否</el-radio>
        </el-form-item>

        <!-- <el-form-item label="Active" prop="active">
          <el-input v-model="form.active" placeholder="请输入Active" />
        </el-form-item> -->
        <el-form-item label="颜色" prop="color">
          <el-input v-model="form.color" placeholder="请输入颜色" />
        </el-form-item>
        <!-- <el-form-item label="创建者id" prop="createUid">
          <el-input v-model="form.createUid" placeholder="请输入创建者id" />
        </el-form-item> -->
        <!-- <el-form-item label="创建日期" prop="createDate">
          <el-date-picker clearable v-model="form.createDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择创建日期">
          </el-date-picker>
        </el-form-item> -->
        <!-- <el-form-item label="最后更新者id" prop="writeUid">
          <el-input v-model="form.writeUid" placeholder="请输入最后更新者id" />
        </el-form-item> -->
        <!-- <el-form-item label="最后更新日期" prop="writeDate">
          <el-date-picker clearable v-model="form.writeDate" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择最后更新日期">
          </el-date-picker>
        </el-form-item> -->

        <el-form-item label="初始库存" prop="quantyWhenInsert">
          <el-input v-model.number="form.quantyWhenInsert" placeholder="请输入初始库存" :disabled="true" />
        </el-form-item>

        <!-- <el-form-item label="仓库(海内外)" prop="warehouse">
          <el-radio v-model="form.warehouse" label="国内">国内仓</el-radio>
          <el-radio v-model="form.warehouse" label="海外">海外仓</el-radio>
        </el-form-item>
        <el-form-item label="库存不足预警数量" prop="productMinQty">
          <el-input v-model.number="form.productMinQty" placeholder="请输入库存不足预警数量" />
        </el-form-item>
        <el-form-item label="补货推荐数量" prop="productMaxQty">
          <el-input v-model.number="form.productMaxQty" placeholder="请输入补货推荐数量" />
        </el-form-item>
        <el-form-item label="供应商" prop="partnerId">
          <el-select v-model="form.partnerId" filterable placeholder="请选择供应商">
            <el-option v-for="item in supplierdata" :key="item.id" :label="item.name" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="最低采购数量" prop="purchaseMinQty">
          <el-input v-model.number="form.purchaseMinQty" placeholder="请输入最低采购数量" />
        </el-form-item>
        <el-form-item label="供应商报价" prop="price">
          <el-input v-model="form.price" placeholder="请输入供应商报价" />
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listStock, getStock, delStock, addStock, updateStock, getOperationdetailsAPI, uom } from "@/api/system/stock";
import { listPartner, getPartner, delPartner, addPartner, updatePartner, getdetail } from "@/api/system/partner";
import stockdetail from '@/views/system/stockdetail/index'
export default {
  name: "Stock",
  dicts: ['product_type', 'product_category', 'stock_uom'],
  data() {
  
    return {
     
      // 单位数组
      uomList: [],
      yesOrnot: [{
        id: "t",
        name: '是'
      },
      {
        id: "f",
        name: '否'
      }],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 库存表格数据
      stockList: [],
      // 弹出层标题
      title: "",
      // 新增显示弹出层
      open: false,
      // 修改弹出框
      openedit: false,
      // 是否显示操作详情弹出层
      op: false,
      // 数据详情
      tableData: [],
      // 是否显示详情弹出层
      dialogVisible: false,
      // 详情返回值
      result: {},
      // 仓库(海内外)时间范围
      daterangeCreateDate: [],
      // 仓库(海内外)时间范围
      daterangeWriteDate: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        sequence: null,
        description: null,
        descriptionPurchase: null,
        descriptionSale: null,
        type: null,
        categId: null,
        listPrice: null,
        volume: null,
        weight: null,
        saleOk: null,
        purchaseOk: null,
        uomId: null,
        active: null,
        color: null,
        createUid: null,
        createDate: null,
        writeUid: null,
        writeDate: null,
        specification: null,
        canBeExpensed: null,
        warehouse: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        // id: [
        //   { required: true, message: "id不能为空", trigger: "blur" }
        // ],
        quantyWhenInsert: [{
          required: true, message: "初始库存不能为空", trigger: "blur"
        },
        { type: 'number', message: '库存预警数量只能输入整数', trigger: 'blur' }]
        ,
        uomId: [
        // { required: true, message: '请选择活动区域', trigger: 'change' }
          { required: true, message: "单位不能为空", trigger: ['change', 'blur'] }
          // , { validator: checkmm }
        ],
        saleOk: [
          { required: true, message: "可用于销售不能为空", trigger: "change" }
        ],
        purchaseOk: [
          { required: true, message: "可用于采购不能为空", trigger: "blur" }
        ],
        canBeExpensed: [
          { required: true, message: "可用于费用不能为空", trigger: "blur" }
        ],
        name: [
          { required: true, message: "名称不能为空", trigger: "blur" }
        ],
        type: [
          { required: true, message: "类型不能为空", trigger: "change" }
        ],
        categId: [
          { required: true, message: "内部类别不能为空", trigger: "change" }
        ],
        price: [{ required: true, message: '供应商报价不能为空' },
        { pattern: /^[+-]?(0|([1-9]\d*))(\.\d+)?$/g, message: '供应商报价只能输入数字', trigger: 'blur' }

        ],
        purchaseMinQty: [
          { required: true, message: "最低采购数量不能为空", trigger: "blur" },
          { type: 'number', message: "最低采购数量只能输入数字", trigger: "blur" }
        ],
        partnerId: [
          { required: true, message: "供应商不能为空", trigger: "blur" }
        ],
        productMinQty: [{ required: true, message: '库存预警数量不能为空' },
        { type: 'number', message: '库存预警数量只能输入整数', trigger: 'blur' }

        ],
        productMaxQty: [
          { required: true, message: "补充推荐数量不能为空", trigger: "blur" },
          { pattern: /^[+]{0,1}(\d+)$/, message: "补充推荐数量只能输入正整数", trigger: "blur" }
        ],
      },
      rules2: {
        // id: [
        //   { required: true, message: "id不能为空", trigger: "blur" }
        // ],
        // quantyWhenInsert: [{
        //   required: true, message: "初始库存不能为空", trigger: "blur"
        // },
        // { type: 'number', message: '库存预警数量只能输入整数', trigger: 'blur' }]
        // ,
        uomId: [
          { required: true, message: "单位不能为空", trigger: ["blur", 'change'] }
        ],
        saleOk: [
          { required: true, message: "可用于销售不能为空", trigger: "blur" }
        ],
        purchaseOk: [
          { required: true, message: "可用于采购不能为空", trigger: "blur" }
        ],
        canBeExpensed: [
          { required: true, message: "可用于费用不能为空", trigger: "blur" }
        ],
        name: [
          { required: true, message: "名称不能为空", trigger: "blur" }
        ],
        type: [
          { required: true, message: "类型不能为空", trigger: "change" }
        ],
        categId: [
          { required: true, message: "内部类别不能为空", trigger: "change" }
        ],
        price: [{ required: true, message: '供应商报价不能为空' },
        { pattern: /^[+-]?(0|([1-9]\d*))(\.\d+)?$/g, message: '供应商报价只能输入数字', trigger: 'blur' }

        ],
        purchaseMinQty: [
          { required: true, message: "最低采购数量不能为空", trigger: "blur" },
          { type: 'number', message: "最低采购数量只能输入数字", trigger: "blur" }
        ],
        partnerId: [
          { required: true, message: "供应商不能为空", trigger: "blur" }
        ],
        productMinQty: [{ required: true, message: '库存预警数量不能为空' },
        { type: 'number', message: '库存预警数量只能输入整数', trigger: 'blur' }

        ],
        productMaxQty: [
          { required: true, message: "补充推荐数量不能为空", trigger: "blur" },
          { pattern: /^[+]{0,1}(\d+)$/, message: "补充推荐数量只能输入正整数", trigger: "blur" }
        ],
      },
      // 供应商列表,用于下拉框
      supplierdata: []
    };
  },
  created() {
    this.getList();
    this.supplierList();
    this.getUom()
  },
  methods: {
    /** 查询库存列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeCreateDate && '' != this.daterangeCreateDate) {
        this.queryParams.params["beginCreateDate"] = this.daterangeCreateDate[0];
        this.queryParams.params["endCreateDate"] = this.daterangeCreateDate[1];
      }
      if (null != this.daterangeWriteDate && '' != this.daterangeWriteDate) {
        this.queryParams.params["beginWriteDate"] = this.daterangeWriteDate[0];
        this.queryParams.params["endWriteDate"] = this.daterangeWriteDate[1];
      }
      listStock(this.queryParams).then(response => {
        this.stockList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.dialogVisible = false;
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        sequence: null,
        description: null,
        descriptionPurchase: null,
        descriptionSale: null,
        type: null,
        categId: null,
        listPrice: null,
        volume: null,
        weight: null,
        saleOk: null,
        purchaseOk: null,
        uomId: null,
        active: null,
        color: null,
        createUid: null,
        createDate: null,
        writeUid: null,
        writeDate: null,
        specification: null,
        canBeExpensed: null,
        warehouse: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeCreateDate = [];
      this.daterangeWriteDate = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    // 获取单位
    getUom() {
      uom().then(res => {
        // console.log(res);
        this.uomList = res.data
      })
    },
    
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加库存";
      this.form.type = '库存产品';
      this.form.quantyWhenInsert = 0
      this.form.purchaseOk = 't'
      this.form.saleOk = 't'
      this.form.canBeExpensed='t'
      

      
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getStock(id).then(response => {
        // console.log(response);
        this.form = response.data;
        this.openedit = true;
        this.title = "修改库存";

      });
    },
    // 库存详情按钮
    detail(row) {
      const id = row.id
      this.$router.push({
        path: "/stockdetail",
        component: stockdetail,
        redirect: "noRedirect",
        hidden: false,
        alwaysShow: true,
        // query: { listId: 10183 },
        query: { listId: id },

      });
      // getStock(id).then(response => {
      //   console.log(response);
      //   // this.form = response.data;
      //   // this.result = response.data
      //   // this.dialogVisible = true;
      //   // this.title = "库存详情";
      // });
    },
    // 操作详情按钮
    Operationdetail(row) {
      const id = row.id;
      this.op = true
      getOperationdetailsAPI(id).then(response => {
        // console.log(response);
        this.tableData = response.data;
        this.title = "操作详情";
      });
    },
    // 下拉框选择供应商
    supplierList() {
      listPartner(this.queryParams).then(res => {
        // console.log(res);
        this.supplierdata = res.rows
        // console.log(this.supplierdata);

      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateStock(this.form).then(response => {
              // console.log(response);
              this.$modal.msgSuccess("修改成功");
              this.openedit = false;
              this.getList();
            });
          } else {
            addStock(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除库存名称为"' + row.name + '"的产品？').then(function () {
        return delStock(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/stock/export', {
        ...this.queryParams
      }, `stock_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
